package com.example.controller;

import com.example.pojo.dto.ProblemDTO;
import com.example.service.ProblemService;
import com.example.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/21
 */
@RestController
@RequestMapping("problem")
public class ProblemController {
    @Autowired
    private ProblemService problemService;
    @PostMapping("saveProblem")
    public Result save(Integer jsId,Integer jrId,String problem){
        System.out.println(jsId+":"+jrId+","+problem);
        if (jsId==null||jrId==null){
            return new Result(404,"提问失败");
        }else {
            int count = problemService.saveProblem(jsId,jrId,problem);
            if (count==1){
                return new Result(200,"发布提问成功");
            }else {
                return new Result(500,"发布失败");
            }
        }
    }
    @PostMapping("searchProblem")
    public Result searchProblem(Integer jrId){
        List<ProblemDTO> list = problemService.findProblemByJrId(jrId);
        return new Result(200,"查询问题成功",list);
    }
    @PostMapping("addLikeNum")
    public Result addLikeNum(Integer jsId,String clickId){
        int count = problemService.addProblemLikeNum(jsId,clickId);
        if (count==1){
            return new Result(200,"点赞成功");
        }else {
            return new Result(500,"点赞失败");
        }
    }
    @PostMapping("delLikeNum")
    public Result delLikeNum(Integer jsId,String clickId){
        int count = problemService.delProblemLikeNum(jsId,clickId);
        if (count==1){
            return new Result(200,"取消点赞");
        }else {
            return new Result(500,"取消点赞失败");
        }
    }
    @PostMapping("searchClickProblem")
    public Result searchClickProblem(Integer jsId,Integer clickIdentification){
        List<String> list = problemService.searchClick(jsId, clickIdentification);
        return new Result(200,"点赞的id",list);
    }
}
